﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MLP.NeuralNet
{
    /// <summary>
    /// Stellt den Client des Rechenlog bereit
    /// </summary>
    public static class cls_Rechen_LOG
    {
        /// <summary>
        /// Geschwindigkeitsvorteil gegenüber string
        /// </summary>
        private static StringBuilder _INH = new StringBuilder();

        private static System.IO.StreamWriter _FS;

        /// <summary>
        /// Fügt enie zeile zum LOG hinzu
        /// </summary>
        /// <param name="txt"></param>
        public static void WRITE_LOG_LINE(string txt)
        {
            if (_INH.Length > 15000)
                _INH.Clear();
            _INH.Append(txt + "\r\n");
        }

        /// <summary>
        /// Leert den Speicher und bereitet eine neue Sitzung vor
        /// </summary>
        public static void RESET()
        {
            cls_Rechen_LOG._INH.Clear();
            
            if(cls_Rechen_LOG._FS != null)
                cls_Rechen_LOG._FS.Close();

            cls_Rechen_LOG._FS = null;
        }

        /// <summary>
        /// Ruft den Wert ab und leer den cache
        /// </summary>
        /// <returns></returns>
        public static string VALUE()
        {
            string txt = "";
            
            try
            {
                txt = cls_Rechen_LOG._INH.ToString();
            }catch(Exception ex)
            {
                txt = ex.Message;
            }

            cls_Rechen_LOG._INH.Clear();
            return txt;
        }
    }
}
